package cn.hotel.service.impl;


import cn.hotel.entity.RoomType;
import cn.hotel.mapper.RoomTypeMapper;
import cn.hotel.service.RoomTypeService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class RoomTypeServiceImpl implements RoomTypeService {

    @Resource
    private RoomTypeMapper roomTypeMapper;

    @Override
    public int updateRoomRest(Integer typeId,String operate) {
        return roomTypeMapper.updateRoomRest(typeId,operate);
    }


    @Override
    public List<RoomType> queryAllRoomType() {
        return roomTypeMapper.queryAllRoomType();
    }

    //配置分页
    @Override
    public PageInfo<RoomType> queryList(Integer page, Integer pageSize) {
        PageHelper.startPage(page , pageSize);
        PageInfo<RoomType> pageInfo = new PageInfo<>(roomTypeMapper.queryAllRoomType());
        return pageInfo;
    }

    @Override
    public RoomType queryRoomTypeByRoomTypeId(Integer typeId) {
        return roomTypeMapper.getRoomTypeByRoomTypeId(typeId);
    }

    //更新roomType信息
    @Override
    public void updateRoomType(RoomType roomType) {
        //查询该房间类别信息
        RoomType roomType2 = roomTypeMapper.getRoomTypeByRoomTypeId(roomType.getTypeId());
        if(roomType2 != roomType){
            //如果发现数据进行了修改那么就进行更新操作
            roomTypeMapper.updateRoomType(roomType);
        }
    }

    //插入roomType信息
    @Override
    public void insertRoomType(RoomType roomType) {
        roomTypeMapper.insertRoomType(roomType);
    }

    //根据id删除房间类别信息
    @Override
    public void deleteRoomTypeByRoomId(int roomId) {
        roomTypeMapper.deleteRoomTypeByRoomId(roomId);
    }
}
